package wanmei;

import java.util.Arrays;

/**
 * @author xizizzz
 * @description: TODO
 * @date 2021-9-7下午 08:19
 */
public class Test2 {
    public static void main(String[] args) {
    }

    public int purchaseCourses(int[] prices, int pocket) {
        int res = 0;
        Arrays.sort(prices);
        for (int i = 0; i < prices.length; i++) {
            if (prices[i] > pocket) {
                prices = Arrays.copyOf(prices, i);
            }
        }
        for (int i = 0; i < prices.length; i++) {
            if (prices[i] > pocket) break;
            for (int j = i + 1; j < prices.length; j++) {

                if ((prices[i] + prices[j] > pocket) || (prices[i] > pocket)) {
                    break;
                }
                if (prices[i] + prices[j] <= pocket) {
                    res = (res + 1) % 1000000007;
                }
            }
        }
        return res;
    }
}
